<include file="Public:header" />
<include file="Public:leftside" />
<div class="main-content">
	<div class="breadcrumbs breadcrumbs-fixed" id="breadcrumbs">
		<ul class="breadcrumb">
			<li> <i class="icon-home home-icon"></i> <a href="/">首页</a> </li>
			<li><a href="javascript:;">广告管理</a></li>
	
		</ul>
	</div>
	<div class="page-content">
  
    <div class="listContent">

    	<div class="wrap js-check-wrap">
  
    <form method="post" class="js-ajax-form" action="{:U('shop/adItemOrders',array('id'=>$adData['id']))}">
      <div class="table-actions" style="margin: 10px 0;">
       

        <button type="submit" class="btn btn-sm btn-primary js-ajax-submit">排序</button>
			<a class="btn btn-sm btn-danger" href="javascript:deleteItemlAD();">删除</a>
			<a class="btn btn-sm btn-primary" href="{:U('Shop/sliderAD')}">返回分类</a>
			<a class="btn btn-sm btn-primary" href="{:U('Shop/addSliderAdItem',array('id'=>$_GET['id'],'ad_name'=>$_GET['ad_name']))}">添加广告</a>

      </div>
      <table class="table table-hover table-bordered table-list">
        <thead>
           <tr>
				<th width="15"><label><input type="checkbox" class="check-all" data-target="ids"></label></th>
				<th width="50">排序</th>
				<th width="50">ID</th>
				<th>广告标题</th>
				<th>次级广告标题</th>
				<th>广告副标题</th>
				<th>广告时间段</th>
				<th>广告分类</th>
				<th>所属广告</th>
				<th>状态</th>
				<th>操作</th>
			</tr>
        </thead>
        <tbody id="adList">
		</tbody>
        <tfoot>
            <tr>
				<th width="15"><label><input type="checkbox" class="check-all" data-target="ids"></label></th>
				<th width="50">排序</th>
				<th width="50">ID</th>
				<th>广告标题</th>
				<th>次级广告标题</th>
				<th>广告副标题</th>
				<th>广告时间段</th>
				<th>广告分类</th>
				<th>所属广告</th>
				<th>状态</th>
				<th>操作</th>
			</tr>
        </tfoot>
      </table>
   
    </form>
  </div>
    </div>
   </div>
</div>

<script>
//全局变量
    var GV = {
         DIMAUB: "/",
        JS_ROOT: "NewAdmin/js/",
        TOKEN: ""
    };
</script>
<script src="/NewAdmin/js/wind.js"></script>
<link href="/NewAdmin/js/artDialog/skins/default.css" rel="stylesheet" />
<script src="/NewAdmin/js/zhlmy.js"></script>
  
  <script>
  	var deleteAdURL="{:U('shop/deleteSliderAdItem')}";
	var editAdURL="{:U('shop/editSliderAdItem',array('id'=>$adData['id'],'ad_name'=>$_GET['ad_name']))}";
	var neweditAdURL=editAdURL.replace(".html","");
	var adData='{$adData.ad_data}';
	var id='{$adData.id}';
	var ad_name='{$ad_name}';
	var ad_type_name='{$adData['ad_type_name']}';
	 
	$(function(){
		if(adData!==''){
			adData=$.parseJSON(adData);
			var adListWrapper=$('#adList');
			var status='';
			var preIndex=0;
			var preInsertADList=null;
			var sortKey='listorder';
			insertSort(adData.AdItem,'listorder',true);

			$.each(adData.AdItem,function(index,Item){
				var adListHtml='';
				status=Item.ad_status==0?'禁用':'投放中';
				//排序后的原key值需要保留，没有oldKey表示用的是原key，直接使用index
				oldKey=Item.oldKey!==undefined?Item.oldKey:index;
				start_time=Item.start_time==''?'不限起始时间':Item.start_time;
				end_time=Item.end_time==''?'不限结束时间':Item.end_time;

				adListHtml+='<tr data-id="'+oldKey+'">'
							+'<td><input type="checkbox" class="js-check" data-name="ids" name="ids[]" value="'+oldKey+'" title="ID:'+oldKey+'"></td>'
							+'<td><input name="listorders['+oldKey+']" type="text" size="3" value="'+Item.listorder+'" class="input input-order valid" aria-invalid="false"></td>'
							+'<td>'+oldKey+'</td><td><img src="'+Item.UpFilePathInfo+'" height="30" style="margin-right:10px">'+Item.ad_title+'</td><td>'+Item.second_title+'</td><td>'+Item.sub_title+'</td><td>'
							+start_time+' 至 '+end_time+'</td><td>'+ad_type_name+'</td><td>'+ad_name+'</td><td>'+status+'</td><td>'
							+'<a href="'+neweditAdURL+'/adKey/'+oldKey+'">编辑</a>'
							+' | <a href="javascript:deleteItemlAD('+oldKey+')">删除</td></tr>';

					adListWrapper.append(adListHtml);
			

			})
			//绑定全选
			$('table').setAllCheckbox();
		}
	})
	//删除广告项
	function deleteItemlAD(adKey){
		//未传递adKey参数时表示批量删除
		if(adKey==undefined){
			var checkItem=$('table :checkbox:checked');
			if(checkItem.length==0){
				alert('请至少选择一个需要操作的对象！');
				return false;
			}

			var adKey='';
			$.each(checkItem,function(){
				adKey+=adKey==''?$(this).val():','+$(this).val();
			})
		}

		$.post(deleteAdURL,{id:id,adKey:adKey},function(data){
			if(data.status==1){	
				//console.log(data.data)
				window.location.reload();
			}else{
				alert(data.error);
			}
		}).error(function(){

			alert('链接服务器出错，无法保存广告项数据，请稍候尝试！');
		})
	}
  </script>
<include file="Public:footer" />
